# compiler, loader etc
CC=gcc

# compilerflags:
CFLAGS = -std=c99 -g -Wall -I . -MMD

# linkerflags, for linking the o-files
LDFLAGS = -g -lpthread -lm

# sources, find all c-files dynamically
SOURCES = $(shell find . -name "*.c")

# target, what to build (name of exec)
TARGET=airport


# default rule, make target
all: $(TARGET)


# create dependencies, created when we use -MMD
DEPS = $(shell find -name "*.d")

# find all objects, remove .c and add .o to name)
OBJECTS = $(SOURCES:.c=.o)

# link progam:
# cannot use $< to list all objects here, use $(OBJECTS)
airport: $(OBJECTS)
	gcc $(LDFLAGS) -o $@ $(OBJECTS)


# compile all object-files
# $@ : output (%.o)
# $< : the name of the input (%.c)
%.o : %.c
	gcc $(CFLAGS) -c $<

# include dependencies, if any
ifneq ($(DEPS),"")
include $(DEPS)
endif


# rule for cleaning up
clean:
	rm -f $(TARGET) $(DEPS) $(OBJECTS) *~ \#*

rebuild: clean all

.PHONY: all rebuild clean

